import common from "../../../utils/common.js";
const app = getApp()
const ip = app.globalData.ipStr
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const { voiceSvgSrc, maleSvgSrc, femaleSvgSrc } = require('../../../utils/iconSvg')
const defaultColor = '#A6A6A6'
// const defaultColor = 'rgba(153,153,153, 1)';
const activeColor = 'rgba(255, 127, 80)';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        defaultAvatarUrl: defaultAvatarUrl,
        userInfoVO: {},
        houseInfoPageVOLPage: {},
        houseNeedPageVOPage: {},
        voiceSvgSrc: voiceSvgSrc(defaultColor),
        maleSvgSrc: maleSvgSrc(defaultColor),
        femaleSvgSrc: femaleSvgSrc(defaultColor),
    },

    getMainDataById(id, fromType) {
        wx.request({
            url: 'http://' + ip + '/weixin/getMainDataById?id=' + id + '&fromType=' + fromType,
            method: 'POST',
            header: {
                'content-type': 'application/json;charset=UTF-8'
            },
            data: {},
            success: res => { //wx.request成功的回调
                console.info('加载用户主页详细信息返回信息=' + JSON.stringify(res))
                if (res.statusCode == 200) {
                    var mainVO = res.data.data
                    this.setData({
                        userInfoVO: mainVO.userInfoVO, houseInfoPageVOLPage: mainVO.houseInfoPageVOLPage,
                        houseNeedPageVOPage: mainVO.houseNeedPageVOPage
                    })

                    if (mainVO == null) {
                        console.error('加载用户主页详细数据异常，请检查')
                    }
                }
            }
        })
    },

    /**
      * 点击 房屋信息 跳转到详情页
      * @param {房屋} e 
      */
    toHouseInfo: function (e) {
        var houseId = e.currentTarget.dataset.id
        console.info('house=' + houseId)
        wx.navigateTo({
            url: '/pages/nuan/info/houseInfo?houseId=' + houseId,
            success: function (res) {
                console.info('打开info页面成功')
            },
            fail: function (e) {
                console.info('打开info页面失败，e=' + JSON.stringify(e))
            }
        })
    },

    clickNeedHouse(e) {
        var id = e.currentTarget.dataset.id;
        var url = '/pages/nuan/need-info/needInfo?id=' + id;
        common.navigateTo2(url);
    },
    /**
    * 
    * @param {跳转到筛选页面} e 
    */
    toPreSelectHouse: function (e) {
        var url = '/pages/nuan/pre-select/preSelect?type=0';
        common.navigateTo2(url)
    },

        /**
    * 
    * @param {跳转到需求列表页面} e 
    */
   toNeedPage: function (e) {
    var url = '/pages/nuan/need-page/needPage';
    common.navigateTo2(url)
},

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var id = options.id
        var fromType = options.fromType
        if (id != undefined && fromType != undefined) {
            if (wx.getStorageSync("token")) {
                this.getMainDataById(id, fromType);
            } else {
                app.login_1128_2().then(tokenStr => {
                    this.getMainDataById(id, fromType);
                })
            }
        }

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})